package Util::FilePath;

use strict;
use warnings;
use vars qw{ @ISA @EXPORT };
use Exporter;
use File::Copy;

@ISA = qw( Exporter );
@EXPORT = qw (  
	IsReadableFile UpdateFileMTime UpdateFileATime DelFiles
);


sub IsReadableFile
#*****************************************************************************
# PURPOSE:
# USAGE:
# PASSED ARGS:
# RETURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
    my ( $sSrcFileName ) = shift;
    return 0 if not $sSrcFileName;
    
	return 0 if not -f $sSrcFileName or
                not -r _;
    return 1;
}

sub UpdateFileMTime
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RTURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my ( $sSrcFileName ) = shift;
	return 0 if not IsReadableFile( $sSrcFileName ); 
	
	my ( $sNow ) = time();
	my ( $sNewMTime ) = $_[ 0 ] || $sNow;
	
	return utime( $sNow,  $sNewMTime, $sSrcFileName );
}

sub UpdateFileATime
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RTURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my ( $sSrcFileName ) = shift;
	return 0 if not IsReadableFile( $sSrcFileName ); 
	
	my ( $sOldMTime ) = ( stat( $sSrcFileName ) )[ 9 ];
	my ( $sNow )= time();
	my ( $sNewATime ) = $_[ 0 ] || $sNow;
	
	return utime( $sNewATime,  $sOldMTime, $sSrcFileName );	
} 

sub DelFiles
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RTURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	return 0 if not @_;
	
	my @aSuccessDelFiles;
	my $sFileNum = scalar @_;
	foreach ( @_ ){
		push  @aSuccessDelFiles, $_ if( unlink( $_ ) );
	}
	return wantarray() ?  
		@aSuccessDelFiles :	$#aSuccessDelFiles + 1;
}

sub X
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RTURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	





}










1
__END__;
